//
//  PeopleXYView.m
//  intelligent
//
//  Created by 甘世清 on 2024/2/26.
//

#import "PeopleXYView.h"

@implementation PeopleXYView

- (void)SQ_UIViewForSelfView{
    UIImageView * bgImage = [[UIImageView alloc]init];
    bgImage.image = SQGetImage(@"协议背景");
    bgImage.layer.cornerRadius = 16;
    bgImage.backgroundColor = UIColor.whiteColor;
    [self addSubview:bgImage];
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(24, 26, 0, 26));
    }];
    UIImageView * image = [[UIImageView alloc]init];
    image.image = SQGetImage(@"隐私协议");
    image.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(80);
        make.height.mas_equalTo(60);
            make.top.centerX.equalTo(self);
    }];
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"隐私协议");
    label.font = FONT_MEDIUM(18);
    label.textColor = SQColor333333;
    [image addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image);
            make.top.equalTo(image.mas_bottom);
    }];
    [self addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bgImage).insets(UIEdgeInsetsMake(85, 16, 10, 16));
    }];
    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: @"https://chatai.funlovemore.top/#/agreementInfo?id=2"]]];
}



-(WKWebView *)webView{
    if (_webView == nil) {
        NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
               
               WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
               WKUserContentController *wkUController = [[WKUserContentController alloc] init];
               [wkUController addUserScript:wkUScript];
               
               WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
               wkWebConfig.userContentController = wkUController;
               
               // 创建设置对象
               WKPreferences *preference = [[WKPreferences alloc]init];
               // 设置字体大小(最小的字体大小)
               preference.minimumFontSize = 15;
               // 设置偏好设置对象
               wkWebConfig.preferences = preference;
               WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkWebConfig];
               webView.scrollView.alwaysBounceVertical = NO;
        webView.backgroundColor = UIColor.clearColor;
        webView.scrollView.backgroundColor = UIColor.clearColor;
        webView.opaque = NO;
        _webView = webView;
    }
    return _webView;
}

@end
